﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using System.Data;

namespace Baosight.Ccs.Mail.Handlers
{
    /// <summary>
    /// 当邮件满足特定条件时将邮件转发
    /// </summary>
    public class RedirectHandler:IMailHandler 
    {

        private MatchingCondition criteria;

        public RedirectHandler(MatchingCondition criteria)
        {
            this.criteria = criteria;
        }

        #region IMailHandler Members

        public bool Process(Mail mail)
        {
            string redirectionAddress = criteria(mail);
            if ( !String.IsNullOrEmpty(redirectionAddress))
            {
                //make it a new mail
                mail.MailId = Guid.NewGuid();
                mail.ToAddress = redirectionAddress;
                mail.Subject = "FWD:" + mail.Subject;
                MailManager.Instance.SendMail(mail);
                return true;
            }
            return false;
        }

        #endregion
    }


    public delegate string MatchingCondition(Mail mail);


}
